import random
import math

alist=[random.randint(-100,100) for x in range(10)]
print(alist)
print(sorted(alist))
print(sorted(alist,reverse=True))
print(sorted(alist,key=abs,reverse=True))
alist2=["as",'DD','wq','Po',"sa"]
# 按照ascii码从小到大进行排序
print(sorted(alist2))
# 忽略字母的大小写
print(sorted(alist2,key=str.lower))
# for x in range(10):
#     alist.append(random.randint(0,100))
class Student:
    def __init__(self,name,age):
        self.age=age
        self.name=name
    def __str__(self):
        return 'age:'+str(self.age)+',name:'+self.name
s1=Student('a',13)
s2=Student('s',18)
s3=Student('c',8)

for y in sorted([s1,s2,s3],key=lambda x:x.name.lower()):
    print(y)
# 闭包的使用
def funout(num1):
    def funIn(num2):
        return num1+num2
    return funIn
myfun1=funout(10)
print(myfun1(90))
# 使用闭包计算两点之间的距离
def DisOut(x1,y1):
    def DisIn(x2,y2):
        return math.sqrt((x2-x1)**2+(y2-y1)**2)
    return DisIn

myfunx=DisOut(0,0)
print(myfunx(1,2))